/*
 * @(#)ADLDoc.java   09/10/12
 * 
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 */



/**
 *
 */
package fr.ema.arch3d.model.architecture.textADL;

import java.awt.Color;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;

//~--- classes ----------------------------------------------------------------

/**
 * class description
 *
 * @version    version 11 oct. 2009
 * @author     Huaxi (Yulin) ZHANG
 */
public class ADLDoc extends DefaultStyledDocument {

    /**
     * Constructs...
     *
     */
    public ADLDoc() {
        super();

        // TODO Auto-generated constructor stub
    }

    /**
     * Method description
     *
     * @param str
     */
    public void insertYellow_Bold_20(String str) {
        SimpleAttributeSet attrset = new SimpleAttributeSet();

        StyleConstants.setForeground(attrset, Color.yellow);
        StyleConstants.setBold(attrset, true);
        this.insert(str, attrset);
    }

    /**
     * Method description
     *
     * @param str
     */
    public void insertBlue_Italic_Bold_22(String str) {
        SimpleAttributeSet attrset = new SimpleAttributeSet();

        StyleConstants.setForeground(attrset, Color.blue);
        StyleConstants.setItalic(attrset, true);
        StyleConstants.setFontSize(attrset, 24);
        insert(str, attrset);
    }

    /**
     * Method description
     *
     * @param str
     */
    public void insertBold(String str) {
        SimpleAttributeSet attrset = new SimpleAttributeSet();

        StyleConstants.setBold(attrset, true);

        // StyleConstants.setFontSize(attrset,22);
        insert(str, attrset);
    }

    /**
     * Method description
     *
     * @param str
     * @param attrset
     */
    public void insert(String str, AttributeSet attrset) {
        try {
            this.insertString(this.getLength(), str, attrset);
        } catch (BadLocationException ble) {
            System.out.println("BadLocationException:" + ble);
        }
    }

    /**
     * Method description
     *
     * @param str
     */
    public void insert(String str) {
        try {
            this.insertString(this.getLength(), str, null);
        } catch (BadLocationException ble) {
            System.out.println("BadLocationException:" + ble);
        }
    }

    /**
     * Method description
     *
     */
    public void changeLine() {
        String str = "\n";

        try {
            this.insertString(this.getLength(), str, null);
        } catch (BadLocationException ble) {
            System.out.println("BadLocationException:" + ble);
        }
    }

    /**
     * Method description
     *
     * @param i  
     */
    public void insertSpace(int i) {
        String str = "";

        for (int j = 0; j < i; j++) {
            str = str + " ";
        }

        try {
            this.insertString(this.getLength(), str, null);
        } catch (BadLocationException ble) {
            System.out.println("BadLocationException:" + ble);
        }
    }
}
